﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Activities;
using TransactionServer.General_Classes;
using System.ComponentModel;
using Microsoft.VisualBasic.Activities;

namespace TransactionServer.CRM4Activities
{

    [Designer(typeof(TransactionServer.ActivityDesign.CRM4Activities.CRM4Disassociate))]
    public sealed class CRM4Disassociate : CodeActivity
    {
        // Define an activity input argument of type string
        public InArgument<Entity> Entity1 { get; set; }
        public InArgument<Entity> Entity2 { get; set; }
        public InArgument<Context> Context { get; set; }
        public InArgument<string> Relationship { get; set; }

        public CRM4Disassociate()
        {
            VisualBasicValue<Context> vbArgument = new VisualBasicValue<Context>(Constants.CONTEXT_NAME);
            this.Context = InArgument<Context>.FromExpression(vbArgument);
        }

        // If your activity returns a value, derive from CodeActivity<TResult>
        // and return the value from the Execute method.
        protected override void Execute(CodeActivityContext context)
        {
            // Obtain the runtime value of the Text input argument
            var Entity1 = context.GetValue(this.Entity1);
            var Entity2 = context.GetValue(this.Entity2);
            var Relationship = context.GetValue(this.Relationship);
            var con = context.GetValue(this.Context);
            var conn = (CRM4Connector)con.Connector[Entity1.System];

            conn.UnLinkEntities(Entity1.Name, new Guid(Entity1.Id), Entity2.Name, new Guid(Entity2.Id), Relationship);
        }
    }
}
